<template>
    <div class="clock">{{text}}</div>
</template>

<script>
    export default {
        name: "clock",
        props:{
          lockSeatTime:{
            type:String
          },
          currentTime:{
            type:String
          }
        },
        data(){
          return{
            currentSecond:60,
            currentMinute:'',
            text:''
          }
        },
        mounted() {
          let lockSeatTime = (new Date(this.lockSeatTime)).getTime()
          let currentTime = (new Date(this.currentTime)).getTime()
          let differ = lockSeatTime - currentTime
          let second = differ/1000
          let currentSecond = second%60
          let currentMinute = parseInt(second/60)
          this.currentSecond = currentSecond
          this.currentMinute = currentMinute
          let time = setInterval(()=>{
            if(currentSecond!=0){
              currentSecond --
            }else {
              currentSecond = 59
              currentMinute -=1
            }
            this.text = (currentMinute<10?'0'+currentMinute:currentMinute)+':'+(currentSecond<10?'0'+currentSecond:currentSecond)
            if(currentMinute <= 0 && currentSecond <=0){
              this.$emit('hidden',true)
              clearInterval(time)
            }
          },1000)
        },


    }
</script>

<style scoped>
  .clock{
  }
</style>
